//
//  WYCDrawalsController.m
//  51信用卡
//
//  Created by 中企互联 on 2017/11/2.
//  Copyright © 2017年 中企互联. All rights reserved.
//

#import "WYCDrawalsController.h"
#import "WYCCardlistPickerView.h"
#import "WYCBillModel.h"
#import "RSAUtil.h"

@interface WYCDrawalsController ()
{
    
    UIButton * cardbutton;
    NSString * str;
}


@property (nonatomic,weak) WYCCardlistPickerView *PickerView;

/** 数组*/
@property(nonatomic,strong)NSMutableArray * billarray;
@end

@implementation WYCDrawalsController

- (void)viewDidLoad {
    [super viewDidLoad];
    //setupNav
    [self setupNav];
    
    
    self.billarray = [[NSMutableArray alloc] init];
    //创建界面
    [self setupCreat];
    
    //获取信用卡列表
    [self setupCreditcardlist];
}

- (void)setupCreditcardlist{
    NSString *cardlist = [NSString stringWithFormat:@"%@token=%@",creditcardlist,[WYCAccountTool unarchivetoken]];
    [HttpTool POST:usergetDebitCard params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        WYCLog(@"-------%@",responseObject);
        if ([[responseObject objectForKey:@"code"] intValue ] == 0) {
            NSArray * resultArray = responseObject[@"result"];
            for (NSDictionary * dict in resultArray) {
                WYCBillModel * model = [WYCBillModel mj_objectWithKeyValues:dict];
                model.bank = [NSString stringWithFormat:@"%@(%@)",model.bankName,model.lastNumber];
                [self.billarray addObject:model];
            }
            
        }else{
            
            [SVProgressHUD showImage:[UIImage imageNamed:@""] status:msgStr];
            
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}

#pragma make ------->>setupNav
- (void)setupNav {
    self.navigationItem.title = @"提现";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.navigationController.navigationBar setBarTintColor:WYCMain];
    
    self.view.backgroundColor = WYCGlobalBg;
}
#pragma make ------->>创建界面
- (void)setupCreat{
    
    CGFloat tableviewY = CGRectGetMaxY(self.navigationController.navigationBar.frame);
    //背景图
    UIView * backView = [[UIView alloc] init];
    backView.frame = CGRectMake(0, tableviewY, ScreenWidth, 540 * px);
    backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backView];
    
    
    
    //卡选择
    UILabel *cardlabel = [[UILabel alloc] init];
    cardlabel.frame = CGRectMake(40 * px, 40 * px, ScreenWidth / 5 * 4, 60 * px);
    cardlabel.font = MiddleLight;
    cardlabel.text = @"提现至:";
    [backView addSubview:cardlabel];
    
    
    cardbutton = [[UIButton alloc] init];
    cardbutton.frame = CGRectMake(backView.width / 2, cardlabel.y, backView.width / 2 - 80 * px, cardlabel.height);
    [cardbutton setTitle:@"请选择银行卡 >" forState:UIControlStateNormal];
    cardbutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [cardbutton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    cardbutton.titleLabel.font = [UIFont systemFontOfSize:WyzFont];
    [cardbutton addTarget:self action:@selector(cardButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:cardbutton];
    
    
    
    UIView * cardline = [[UIView alloc] init];
    cardline.frame = CGRectMake(cardlabel.x, CGRectGetMaxY(cardlabel.frame) + 40 * px, ScreenWidth - 80 * px, 0.5);
    cardline.backgroundColor = WYCGlobalBg;
    [backView addSubview:cardline];
    
    //$
    UILabel *maneylabel = [[UILabel alloc] init];
    maneylabel.frame = CGRectMake(40 * px, CGRectGetMaxY(cardline.frame) + 80 * px, backView.width / 4, 60 * px);
    maneylabel.font = MiddleLight;
    maneylabel.text = @"提现金额:";
    [backView addSubview:maneylabel];
    
    UILabel * yuanlabel = [[UILabel alloc] init];
    yuanlabel.frame = CGRectMake(CGRectGetMaxY(maneylabel.frame) + 20 * px, maneylabel.y, backView.width / 4, 60 * px);
//    yuanlabel.text = @"0.00元";
    yuanlabel.textColor = WYCMain;
    [backView addSubview:yuanlabel];
    
    
    UITextField *maneyField = [[UITextField alloc] init];
    maneyField.frame = CGRectMake(ScreenWidth - 450 * px, maneylabel.y, 450 * px, 60 * px);
    maneyField.placeholder = @"输入提现额度";
    maneyField.font = MiddleLight;
    [backView addSubview:maneyField];
    
    
    
    UIView * bottomView = [[UIView alloc] init];
    bottomView.frame = CGRectMake(cardlabel.x, CGRectGetMaxY(maneyField.frame) + 80 * px, ScreenWidth - cardlabel.x, 1);
    bottomView.backgroundColor = WYCGlobalBg;
    [backView addSubview:bottomView];
    
    
    UILabel *balancelabel = [[UILabel alloc] init];
    balancelabel.frame = CGRectMake(40 * px, CGRectGetMaxY(bottomView.frame) + 40 * px, ScreenWidth / 2, 60 * px);
    balancelabel.font = MiddleLight;
    balancelabel.text = @"账户余额：";
    [backView addSubview:balancelabel];
    
    //全部提现
    UIButton *wholeButton = [[UIButton alloc] init];
    wholeButton.frame = CGRectMake(ScreenWidth - 290 * px, balancelabel.y, 250 * px, 60 * px);
    [wholeButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    wholeButton.titleLabel.font = MiddleLight;
    [wholeButton setTitle:@"全部提现" forState:UIControlStateNormal];
    [backView addSubview:wholeButton];
    //提示
    UILabel *showlabel = [[UILabel alloc] init];
    showlabel.frame = CGRectMake(40 * px, CGRectGetMaxY(backView.frame) + 40 * px, ScreenWidth / 3 * 2, 60 * px);
    showlabel.font = smallLight;
    showlabel.textColor = WYZGrayBg;
    showlabel.text = @"单笔提现金额范围：》1.00元";
    [self.view addSubview:showlabel];
    
    
    //提示
    UILabel *showratelabel = [[UILabel alloc] init];
    showratelabel.frame = CGRectMake(ScreenWidth - 440 * px, showlabel.y, 400 * px, 60 * px);
    showratelabel.textAlignment = NSTextAlignmentRight;
    showratelabel.font = smallLight;
    showratelabel.textColor = WYZGrayBg;
    showratelabel.text = @"提现费率：0.8%";
    [self.view addSubview:showratelabel];
    
    
    
    //提交按钮
    UIButton * saveButton = [[UIButton alloc] init];
    saveButton.frame = CGRectMake(40 * px, CGRectGetMaxY(showlabel.frame) + 300 * px, ScreenWidth - 80 * px, 150 * px);
    [saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    saveButton.layer.cornerRadius = 5;
    [saveButton addTarget:self action:@selector(saveButtonClick) forControlEvents:UIControlEventTouchUpInside];
    saveButton.backgroundColor = WYCMain;
    saveButton.titleLabel.font = smallLight;
    [saveButton setTitle:@"确认提现" forState:UIControlStateNormal];
    [self.view addSubview:saveButton];
}
- (void)cardButtonClick
{
    
    WYCLogFunc;
    if (!self.PickerView) {
        
        NSMutableArray *arr = self.billarray;
        WYCCardlistPickerView *PickerView = [[WYCCardlistPickerView alloc]initWithSourceData:arr confirmBlock:^(WYCBillModel * BillModel) {
            
            NSString * Str = [NSString stringWithFormat:@"%@(%@)>",BillModel.bankName,BillModel.lastNumber];
            [cardbutton setTitle:Str forState:UIControlStateNormal];
            //            self.name.text = BillModel.name;
            
            str = BillModel.cardId;
            [self pickerViewhide:YES];
            
            
        } cancelBlock:^(WYCBillModel * BillModel) {
            
            [self pickerViewhide:YES];
            
        }];
        PickerView.frame = CGRectMake(0, ScreenHeight, ScreenWidth, 220);
        [self.view addSubview:PickerView];
        self.PickerView = PickerView;
        [self pickerViewhide:NO];
    }
}


- (void)pickerViewhide:(BOOL)hide {
    
    if (hide) {
        
        [UIView animateWithDuration:1 animations:^{
            
            self.PickerView.frame = CGRectMake(0, ScreenHeight, ScreenWidth, 280);
        }];
    }else {
        
        [UIView animateWithDuration:1 animations:^{
            
            self.PickerView.frame = CGRectMake(0, ScreenHeight - 280, ScreenWidth, 280);
        }];
    }
    
}
#pragma make -------->>确认充值事件
- (void)saveButtonClick{
    WYCLogFunc;
    
}

#pragma make --------->>选择卡
- (void)pushButtonClick{
    
    WYCLogFunc;
}
@end
